<?php
/**
 * Created by PhpStorm.
 * User: sqq
 * Date: 2018/10/24
 * Time: 14:06
 */

class AhpStoreController extends BaseController {

    /**
     * @Author:      sqq
     * @DateTime:    2018-10-24 14:14:39
     * @Description: 用于展示 门店列表
     * @link: http://www.activity.com/ahp/ahp3.0/store/index?token=3bf1ddae386db9708d429e3ac3641be2&page=1&page_size=10&is_show=0&name=%E5%AE%89%E6%83%A0&status=1&city_id=2
     */
    public function index()
    {
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                "page"=>'integer',
                "page_size"=>'integer',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("ahp_error.args_error_1000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $ahp_users=$this->verificationAhpUserToken(Input::get("token"),$response);
            if(is_null($ahp_users)){
                break;
            }

            //查询列表前先同步CMS数据
            $allShop = MaintenanceShops::select('id','name','status','city_id')->get();
            if(!is_null($allShop)){
                foreach($allShop as $key => $val){
                    $shop = AhpMaintenanceShops::where('cms_shop_id',$val->id)->first();
                    try{
                        if(is_null($shop)){
                            $shop = New AhpMaintenanceShops();
                            $shop->cms_shop_id = $val->id;
                            $shop->status = 1;
                            $shop->created_at = Common::currentTimeString();
                            $shop->created_by = $ahp_users->id;
                        }
                        $shop->cms_shop_name = $val->name;
                        $shop->cms_status = $val->status;
                        $shop->city_id = $val->city_id;
                        $shop->updated_at = Common::currentTimeString();
                        $shop->updated_by = $ahp_users->id;
                        $shop->save();
                    }catch (Exception $e){
                        Log::error("error", array("system" => "ahp3.0" ,"event" => "/store/index", 'input' =>Input::all() ,"exception" => $e));
                        $response = Lang::get("ahp_error.wechat3_synchronization_shops_error_50000");
                        break;
                    }
                }
            }

            $page_size=Input::get("page_size",10);
            $page=Input::get("page",1);

            $sr = MaintenanceShops::leftJoin('resource_city_type','maintenance_shops.city_id','=','resource_city_type.id')
                ->leftJoin('ahp_maintenance_shops','maintenance_shops.id','=','ahp_maintenance_shops.cms_shop_id')
                ->leftJoin('ahp_user','ahp_maintenance_shops.updated_by','=','ahp_user.id')
                ->select('ahp_maintenance_shops.id','ahp_maintenance_shops.cms_shop_id','ahp_maintenance_shops.cms_shop_name','ahp_maintenance_shops.ahp_shop_name','ahp_maintenance_shops.status','ahp_maintenance_shops.cms_status','resource_city_type.id as city_id','resource_city_type.name as city_name','ahp_maintenance_shops.cms_status','ahp_maintenance_shops.updated_at','ahp_maintenance_shops.updated_by','ahp_user.real_name')
                ->orderBy('maintenance_shops.id','desc');
            if(Input::get('name')){
                $sr->where('ahp_maintenance_shops.cms_shop_name','like','%'.Input::get('name').'%');
            }
            if(Input::get('status') != ""){
                $sr->where('ahp_maintenance_shops.status',Input::get('status'));
            }
            if(Input::get('is_show') != ""){
                $sr->where('ahp_maintenance_shops.cms_status',Input::get('is_show'));
            }
            if(Input::get('city_id')){
                $sr->where("maintenance_shops.city_id",Input::get('city_id'));
            }
            $count = $sr->count();
            $sr=$sr->skip($page_size*($page-1))->take($page_size)->get();

            //组织返回
            $response = array('code' => 0, 'msg' => 'ok', 'result' => array("count"=>$count,"storeList"=>$sr));
        } while (false);
        Log::info("info", array("system" => "ahp3.0" ,"event" => "/store/index", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }


    /**
     * @Author:      sqq
     * @DateTime:    2018-10-13 10:13:39
     * @Description: 门店信息详情/直播门店直播详情
     * @link: http://www.activity.com/ahp/ahp3.0/store/show?token=a3aeb95a06b53760105d734b9123a3cf&shop_id=15
     */
    public function show(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                "shop_id"=>'required', //cms门店id
            )
        );
        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("ahp_error.args_error_1000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $users=$this->verificationAhpUserToken(Input::get("token"),$response);
            if(is_null($users)){
                break;
            }

            //获取参数
            $shop_id = Input::get("shop_id");

            $sr = AhpMaintenanceShops::with('cityinfo')->where('cms_shop_id',$shop_id)->first();
            if(!is_null($sr)){
                $sr->live = AhpLiveAppKeySecret::where('shop_id',$shop_id)->first();
                $sr->live_currency = AhpLive::where('shop_id',$shop_id)->where('station_id',0)->first();
                $sr->live_station = MaintenanceStation::LeftJoin('ahp_live','ahp_live.station_id','=','maintenance_station.id')->where('maintenance_station.shop_id',$shop_id)->where('maintenance_station.status',1)->select('ahp_live.id','maintenance_station.shop_id','maintenance_station.id as station_id','ahp_live.live_sequence_number','ahp_live.live_equipment_channel','ahp_live.status','maintenance_station.name')->get();
                //print_r(\DB::getQueryLog());die;
                $sr->url = Config::get('store_wechat3.store_wechat3_file_url');
                $sr->service = AhpMaintenanceShopsService::leftjoin('ahp_service','ahp_maintenance_shops_service.service_id','=','ahp_service.id')->where('ahp_maintenance_shops_service.cms_shop_id',$shop_id)->where('ahp_maintenance_shops_service.status',1)->select('ahp_service.service_name','ahp_service.id as service_id','ahp_service.status','ahp_maintenance_shops_service.id','ahp_maintenance_shops_service.ahp_shop_id','ahp_maintenance_shops_service.cms_shop_id','ahp_maintenance_shops_service.sort')->get();
            }

            //组织返回
            $response = array('code' => 0, 'msg' => 'ok', 'result' => $sr);
        } while (false);
        Log::info("info", array("system" => "ahp3.0" ,"event" => "/store/show", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }


    /**
     * @Author:      sqq
     * @DateTime:    2018-11-12 17:36:39
     * @Description: 门店投放
     * @link: http://www.activity.com/ahp/ahp3.0/store/updeteStatus?token=a3aeb95a06b53760105d734b9123a3cf&status=1&shop_id=1
     */
    public function updeteStatus(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                "status"=>'required', // 状态 0-关闭 1-开启
                "shop_id"=>'required', //cms门店id
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        do {
            if ($validator->fails()) {
                $response = Lang::get("ahp_error.args_error_1000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $ahp_users=$this->verificationAhpUserToken(Input::get("token"),$response);
            if(is_null($ahp_users)){
                break;
            }

            //获取参数
            $status = Input::get("status");
            $shop_id = Input::get("shop_id");

            //校验门店信息是否存在
            $shops = AhpMaintenanceShops::where('cms_shop_id',$shop_id)->first();
            if(is_null($shops)){
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_not_error_50001");
                break;
            }

            if($status != 0 && $status != 1){
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_status_not_error_50005");
                break;
            }
            if($shops->status == $status && $status == 1){
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_status_1_error_50003");
                break;
            }
            if($shops->status == $status && $status == 0){
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_status_0_error_50004");
                break;
            }

            try{
                AhpMaintenanceShops::where('cms_shop_id',$shop_id)->update(
                    array(
                        'status' => $status,
                        'updated_at' => Common::currentTimeString(),
                        'updated_by' => $ahp_users->id,
                    )
                );
            }catch (Exception $e){
                Log::error("error", array("system" => "ahp3.0" ,"event" => "/store/updeteStatus", 'input' =>Input::all() ,"exception" => $e));
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_save_error_50002");
                break;
            }

            //组织返回
            $response = array('code' => 0, 'msg' => 'ok');
        } while (false);
        Log::info("info", array("system" => "ahp3.0" ,"event" => "/store/updeteStatus", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }


    /**
     * @Author:      sqq
     * @DateTime:    2018-11-13 12:26:39
     * @Description: 门店信息保存
     * @link: www.activity.com/ahp/ahp3.0/store/store_basic_save?token=5825b9b3e900d9ee45c305fc7b2f4687&shop_id=25&business_start_time=07:00&business_end_time=18:00&address=亚运村&tel_phone=13800000000&first_image=1.jpg&first_h5_image=1.jpg&thumbnail=1.jpg&show_image=1.jpg&wash_start_time=09:00&wash_end_time=17:00&desc=时庆庆修改&longitude=116.513355&latitude=39.899920
     */
    public function store_basic_save(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                "shop_id"=>'required', //cms门店id
                "business_start_time"=>'required',
                "business_end_time"=>'required',
                "address"=>'required',
                "tel_phone"=>'required',
                "first_image"=>'required',
                "first_h5_image"=>'required',
                "thumbnail"=>'required',
                "show_image"=>'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        do {
            if ($validator->fails()) {
                $response = Lang::get("ahp_error.args_error_1000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $ahp_users=$this->verificationAhpUserToken(Input::get("token"),$response);
            if(is_null($ahp_users)){
                break;
            }

            //获取参数
            $shop_id = Input::get("shop_id");

            //校验门店信息是否存在
            $shops = AhpMaintenanceShops::where('cms_shop_id',$shop_id)->first();
            if(is_null($shops)){
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_not_error_50001");
                break;
            }

            try{
                $shops->business_start_time = Input::get('business_start_time');
                $shops->business_end_time = Input::get('business_end_time');
                $shops->address = Input::get('address');
                $shops->tel_phone = Input::get('tel_phone');
                $shops->first_image = Input::get('first_image');
                $shops->first_h5_image = Input::get('first_h5_image');
                $shops->thumbnail = Input::get('thumbnail');
                $shops->show_image = Input::get('show_image');
                $shops->wash_start_time = Input::get('wash_start_time');
                $shops->wash_end_time = Input::get('wash_end_time');
                $shops->desc = Input::get('desc');
                $shops->longitude = Input::get('longitude');
                $shops->latitude = Input::get('latitude');
                $shops->updated_at = Common::currentTimeString();
                $shops->updated_by = $ahp_users->id;
                $shops->save();
            }catch (Exception $e){
                Log::error("error", array("system" => "ahp3.0" ,"event" => "/store/store_basic_save", 'input' =>Input::all() ,"exception" => $e));
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_save_error_50002");
                break;
            }

            //组织返回
            $response = array('code' => 0, 'msg' => 'ok');
        } while (false);
        Log::info("info", array("system" => "ahp3.0" ,"event" => "/store/store_basic_save", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }


    /**
     * @Author:      sqq
     * @DateTime:    2018-11-13 12:26:39
     * @Description: 门店直播保存
     * @link: http://www.activity.com/ahp/ahp3.0/store/store_live_save?token=5825b9b3e900d9ee45c305fc7b2f4687&shop_id=1&live_sequence_number=825955518&live_equipment_channel=1&station_id=0
     */
    public function store_live_save(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                "shop_id" => 'required', //cms门店id
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        do {
            if ($validator->fails()) {
                $response = Lang::get("ahp_error.args_error_1000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $ahp_users=$this->verificationAhpUserToken(Input::get("token"),$response);
            if(is_null($ahp_users)){
                break;
            }

            //获取参数
            $shop_id = Input::get("shop_id");

            //校验门店信息是否存在
            $shops = AhpMaintenanceShops::where('cms_shop_id',$shop_id)->first();
            if(is_null($shops)){
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_not_error_50001");
                break;
            }

            //校验数据
            if((!Input::get('appKey') && Input::get('Secret')) || (!Input::get('Secret') && Input::get('appKey'))){
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_live_basic_not_error_50006");
                break;
            }
            if((!Input::get('live_sequence_number') && Input::get('live_equipment_channel') && Input::get('station_id') == 0) || (!Input::get('live_equipment_channel') && Input::get('live_sequence_number') && Input::get('station_id') == 0)){
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_live_currency_not_error_50007");
                break;
            }
            if((!Input::get('live_sequence_number') && Input::get('live_equipment_channel') && Input::get('station_id') != 0) || (!Input::get('live_equipment_channel') && Input::get('live_sequence_number') && Input::get('station_id') != 0)){
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_live_station_not_error_50008");
                break;
            }

            $live = AhpLiveAppKeySecret::where('shop_id',$shop_id)->first();
            if(is_null($live)){
                $live = new AhpLiveAppKeySecret();
                $live->created_at = Common::currentTimeString();
                $live->created_by = $ahp_users->id;
            }
            $live->shop_id = $shop_id;
            $live->appKey = Input::get('appKey');
            $live->Secret = Input::get('Secret');
            $live->live_sequence_number = Input::get('live_sequence_number');
            $live->live_equipment_channel = Input::get('live_equipment_channel');
            $live->updated_at = Common::currentTimeString();
            $live->updated_by = $ahp_users->id;

            try{
                if(Input::get('live_sequence_number') && Input::get('live_equipment_channel')){
                    $lives = AhpLiveAppKeySecret::where('shop_id',$shop_id)->first();
                    if(is_null($lives)){
                        $response = Lang::get("ahp_error.wechat3_maintenance_shops_live_appKey_Secret_not_error_50009");
                        break;
                    }
                    $station_id = Input::get('station_id');
                    if($station_id != ''){
                        $live_station = AhpLive::where('shop_id',$shop_id)->where('station_id',Input::get('station_id',0))->first();
                        if(is_null($live_station)){
                            $live_station = new AhpLive();
                            $live_station->created_at = Common::currentTimeString();
                            $live_station->created_by = $ahp_users->id;
                        }
                        $live_station->shop_id = $shop_id;
                        $live_station->station_id = $station_id;
                        $live_station->live_sequence_number = Input::get('live_sequence_number');
                        $live_station->live_equipment_channel = Input::get('live_equipment_channel');
                        $live_station->updated_at = Common::currentTimeString();
                        $live_station->updated_by = $ahp_users->id;
                        $live_station->save();

                        $lives->live_sequence_number = Input::get('live_sequence_number');
                        $lives->live_equipment_channel = Input::get('live_equipment_channel');
                        $lives->save();
                    }else{
                        $response = Lang::get("ahp_error.args_error_1000");
                        break;
                    }
                }
                if(Input::get('appKey') && Input::get('Secret')){
                    $live->save();
                }
            }catch (Exception $e){
                Log::error("error", array("system" => "ahp3.0" ,"event" => "/store/store_live_save", 'input' =>Input::all() ,"exception" => $e));
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_save_error_50002");
                break;
            }

            //组织返回
            $response = array('code' => 0, 'msg' => 'ok');
        } while (false);
        Log::info("info", array("system" => "ahp3.0" ,"event" => "/store/store_live_save", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }


    /**
     * @Author:      sqq
     * @DateTime:    2018-11-13 12:26:39
     * @Description: 门店服务保存
     * @link: http://www.activity.com/ahp/ahp3.0/store/store_service?token=5825b9b3e900d9ee45c305fc7b2f4687&service_id=68&sort=1&shop_id=1
     */
    public function store_service(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                'shop_id' => 'required', //cms门店id
                'service_id' => 'required',
                'sort' => 'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        do {
            if ($validator->fails()) {
                $response = Lang::get("ahp_error.args_error_1000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $ahp_users=$this->verificationAhpUserToken(Input::get("token"),$response);
            if(is_null($ahp_users)){
                break;
            }

            //获取参数
            $shop_id = Input::get("shop_id");
            $sort = Input::get("sort");

            //校验门店信息是否存在
            $shops = AhpMaintenanceShops::where('cms_shop_id',$shop_id)->first();
            if(is_null($shops)){
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_not_error_50001");
                break;
            }

            try{
                $services = AhpMaintenanceShopsService::where('cms_shop_id',$shop_id)->where('sort',$sort)->first();
                if(is_null($services)){
                    $services = new AhpMaintenanceShopsService();
                    $services->created_at = Common::currentTimeString();
                    $services->created_by = $ahp_users->id;
                }
                $services->sort = $sort;
                $services->service_id = Input::get('service_id');
                $services->cms_shop_id = $shop_id;
                $services->ahp_shop_id = $shops->id;
                $services->status = 1;
                $services->updated_by = $ahp_users->id;
                $services->updated_at = Common::currentTimeString();
                $services->save();
            }catch (Exception $e){
                Log::error("error", array("system" => "ahp3.0" ,"event" => "/store/store_service", 'input' =>Input::all() ,"exception" => $e));
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_save_error_50002");
                break;
            }

            //组织返回
            $response = array('code' => 0, 'msg' => 'ok');
        } while (false);
        Log::info("info", array("system" => "ahp3.0" ,"event" => "/store/store_service", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }


    /**
     * @Author:      sqq
     * @DateTime:    2018-11-13 12:26:39
     * @Description: 删除门店服务
     * @link: http://www.activity.com/ahp/ahp3.0/store/del_store_service?token=5825b9b3e900d9ee45c305fc7b2f4687&id=1
     */
    public function del_store_service(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                'id' => 'required', //门店推荐服务id  ahp_maintenance_shops_service表里面的id
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        do {
            if ($validator->fails()) {
                $response = Lang::get("ahp_error.args_error_1000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $ahp_users=$this->verificationAhpUserToken(Input::get("token"),$response);
            if(is_null($ahp_users)){
                break;
            }

            //获取参数
            $id = Input::get("id");

            //校验信息是否存在
            $shops_service = AhpMaintenanceShopsService::where('id',$id)->first();
            if(is_null($shops_service)){
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_service_not_error_50010");
                break;
            }

            if($shops_service->status == 2){
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_service_already_del_error_50012");
                break;
            }

            try{
                $shops_service->status = 2;
                $shops_service->updated_at = Common::currentTimeString();
                $shops_service->updated_by = $ahp_users->id;
                $shops_service->save();
            }catch (Exception $e){
                Log::error("error", array("system" => "ahp3.0" ,"event" => "/store/del_store_service", 'input' =>Input::all() ,"exception" => $e));
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_service_del_error_50011");
                break;
            }

            //组织返回
            $response = array('code' => 0, 'msg' => 'ok');
        } while (false);
        Log::info("info", array("system" => "ahp3.0" ,"event" => "/store/del_store_service", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }


    /**
     * @Author:      sqq
     * @DateTime:    2018-11-14 10:22:37
     * @Description: 门店服务列表
     * @link: http://www.activity.com/ahp/ahp3.0/store/storeServiceList?token=5825b9b3e900d9ee45c305fc7b2f4687&shop_id=15
     */
    public function storeServiceList(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                'shop_id' => 'required',
                "page"=>'integer',
                "page_size"=>'integer',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do{
            if($validator->fails()) {
                $response = Lang::get("ahp_error.args_error_1000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $ahp_user=$this->verificationAhpUserToken(Input::get("token"),$response);
            if(is_null($ahp_user)){
                break;
            }
            $page_size=Input::get("page_size",99999);
            $page=Input::get("page",1);

            //查询已经推荐的服务
            $store_service = AhpMaintenanceShopsService::where('cms_shop_id',Input::get('shop_id'))->where('status',1)->select('service_id')->get()->toArray();
            $service = array();
            if(!empty($store_service)){
                $service = array_column($store_service,'service_id');
            }
            $res = AhpService::where('status',1)->orderBy('id','desc')->select('id','service_name','status');
            if(!empty($service)){
                $res = $res->whereNotIn('id',$service);
            }
            $count = $res->count();
            $res=$res->skip($page_size*($page-1))->take($page_size)->get();

            $response = array('code' => 0, 'msg' => 'ok', 'result' => array("count"=>$count,"serviceList"=>$res));

        }while(false);
        Log::info("info", array("system" => "ahp" ,"event" => "/store/storeServiceList", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }


    /**
     * @Author:      sqq
     * @DateTime:    2018-11-14 14:20:39
     * @Description: 修改门店推荐服务状态
     * @link: http://www.activity.com/ahp/ahp3.0/store/save_store_service?token=5825b9b3e900d9ee45c305fc7b2f4687&shop_id=1&is_service=2
     */
    public function save_store_service(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                'shop_id' => 'required',
                'is_service' => 'required', //是否开启门店服务推荐  1-开启 2-关闭
            )
        );
        $response = array('code' => 0, 'msg' => 'ok');
        do {
            if ($validator->fails()) {
                $response = Lang::get("ahp_error.args_error_1000");
                $response["result"]=$validator->messages()->all();
                break;
            }
            $ahp_users=$this->verificationAhpUserToken(Input::get("token"),$response);
            if(is_null($ahp_users)){
                break;
            }

            //获取参数
            $shop_id = Input::get("shop_id");
            $is_service = Input::get("is_service");

            if($is_service != 1 && $is_service != 2){
                $response = Lang::get("ahp_error.args_error_1000");
                break;
            }

            //校验信息是否存在
            $shops = AhpMaintenanceShops::where('cms_shop_id',$shop_id)->first();
            if(is_null($shops)){
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_not_error_50001");
                break;
            }
            if($shops->is_service == 1 && $is_service == 1){
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_service_open_error_50013");
                break;
            }
            if($shops->is_service == 2 && $is_service == 2){
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_service_ont_open_error_50014");
                break;
            }

            try{
                $shops->is_service = $is_service;
                $shops->updated_at = Common::currentTimeString();
                $shops->updated_by = $ahp_users->id;
                $shops->save();
            }catch (Exception $e){
                Log::error("error", array("system" => "ahp3.0" ,"event" => "/store/save_store_service", 'input' =>Input::all() ,"exception" => $e));
                $response = Lang::get("ahp_error.wechat3_maintenance_shops_save_error_50002");
                break;
            }

            //组织返回
            $response = array('code' => 0, 'msg' => 'ok');
        } while (false);
        Log::info("info", array("system" => "ahp3.0" ,"event" => "/store/save_store_service", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }



}